package com.dalin.platform.etl.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import com.dalin.common.base.BaseObject;
import com.dalin.common.utils.StringUtils;
import com.dalin.platform.pub.PlatContext;
/*****************************************************************************
 * @content: 类信息                                                   *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2010-05-11                                                     *
 * @modDate: 2010-05-11                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
@Entity
@Table(name="ETL_COLUMN_INFO")
public class EtlColumnInfoEntity extends BaseObject {
    private Long columnId; // COLUMN_ID,16,0
    private Long tableId;
    private boolean isPrimaryKey; // 是否为主键
    private String columnName; // COLUMN_ENGLISH_NAME,128,0
    private String columnComment; // COLUMN_CHINESE_NAME,256,0
    private Integer columnType; // COLUMN_TYPE,8,0
    private Integer columnLength; // COLUMN_LENGTH,8,0
    private Integer decimalDigits; // COLUMN_LENGTH,8,0
    private Integer nullable; // NULLABLE,2,0
    private String remark; // REMARK,256,0


	@Id
    @Column(name="COLUMN_ID")
    @GeneratedValue(strategy = GenerationType.TABLE,generator="generator_normal")
    @TableGenerator(
        name = "generator_normal",
        table = "GLB_GENERATOR_KEY",
        pkColumnName = "GEN_KEY",
        valueColumnName = "GEN_VALUE",
        pkColumnValue = "ETL_COLUMN_INFO",
        allocationSize=1
    )
    public Long getColumnId() {
        return columnId;
    }

    public void setColumnId(Long columnId) {
        this.columnId = columnId;
    }
    
    @Column(name="TABLE_ID")
    public Long getTableId() {
		return tableId;
	}

	public void setTableId(Long tableId) {
		this.tableId = tableId;
	}

	@Column(name="COLUMN_NAME")
    public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	@Column(name="COLUMN_COMMENT")
	public String getColumnComment() {
		return columnComment;
	}

	public void setColumnComment(String columnComment) {
		this.columnComment = columnComment;
	}

	@Column(name="COLUMN_TYPE")
    public Integer getColumnType() {
        return columnType;
    }

    public void setColumnType(Integer columnType) {
        this.columnType = columnType;
    }

    @Column(name="COLUMN_LENGTH")
    public Integer getColumnLength() {
        return columnLength;
    }

    public void setColumnLength(Integer columnLength) {
        this.columnLength = columnLength;
    }
    
    @Column(name="DECIMAL_DIGITS")
    public Integer getDecimalDigits() {
		return decimalDigits;
	}

	public void setDecimalDigits(Integer decimalDigits) {
		this.decimalDigits = decimalDigits;
	}

    @Column(name="NULLABLE")
    public Integer getNullable() {
        return nullable;
    }

    public void setNullable(Integer nullable) {
        this.nullable = nullable;
    }

    @Column(name="REMARK")
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
   
    @Column(name="IS_PRIMARY_KEY")
    public boolean getIsPrimaryKey() {
		return isPrimaryKey;
	}

	public void setIsPrimaryKey(boolean isPrimaryKey) {
		this.isPrimaryKey = isPrimaryKey;
	}

	@Transient
    public EtlTableInfoEntity getTableInfoEntity() {
		return (EtlTableInfoEntity) PlatContext.getDao()
				.findObjById(EtlTableInfoEntity.class, this.getTableId());
	}
    
    @Transient
    public EtlColumnViewEntity getColumnViewEntity() {
    	List<EtlColumnViewEntity> dataList = PlatContext.getDao()
    			.queryEqualObjs(EtlColumnViewEntity.class,
    						"columnId", this.getColumnId());
    	if (StringUtils.isBlank(dataList)) return null;
		return dataList.get(0);
	}


    @Override
    public int hashCode() {
        int njlrst = 17;
        njlrst = 31 * njlrst + (columnId == null ? 0 : columnId.hashCode());
        njlrst = 31 * njlrst + (tableId == null ? 0 : tableId.hashCode());
        njlrst = 31 * njlrst + (columnName == null ? 0 : columnName.hashCode());
        njlrst = 31 * njlrst + (columnComment == null ? 0 : columnComment.hashCode());
        njlrst = 31 * njlrst + (columnType == null ? 0 : columnType.hashCode());
        njlrst = 31 * njlrst + (columnLength == null ? 0 : columnLength.hashCode());
        njlrst = 31 * njlrst + (nullable == null ? 0 : nullable.hashCode());
        njlrst = 31 * njlrst + (remark == null ? 0 : remark.hashCode());
        return njlrst;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof EtlColumnInfoEntity)) return false;
        final EtlColumnInfoEntity other = (EtlColumnInfoEntity) o;
        if (columnId == null) {
            if (other.columnId != null) return false;
        } else if (!columnId.equals(other.columnId)) {
            return false;
        }
        if (tableId == null) {
            if (other.tableId != null) return false;
        } else if (!tableId.equals(other.tableId)) {
            return false;
        }
        if (columnName == null) {
            if (other.columnName != null) return false;
        } else if (!columnName.equals(other.columnName)) {
            return false;
        }
        if (columnComment == null) {
            if (other.columnComment != null) return false;
        } else if (!columnComment.equals(other.columnComment)) {
            return false;
        }
        if (columnType == null) {
            if (other.columnType != null) return false;
        } else if (!columnType.equals(other.columnType)) {
            return false;
        }
        if (columnLength == null) {
            if (other.columnLength != null) return false;
        } else if (!columnLength.equals(other.columnLength)) {
            return false;
        }
        if (nullable == null) {
            if (other.nullable != null) return false;
        } else if (!nullable.equals(other.nullable)) {
            return false;
        }
        if (remark == null) {
            if (other.remark != null) return false;
        } else if (!remark.equals(other.remark)) {
            return false;
        }
        return true;
    }



}
